package org.sibframework.sda.reflect;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.sibframework.sda.dbmodel.Column;

public class TableType2JavaType {
	public static final String TABLE_NUMBER = "java.math.BigDecimal";
	public static final String TABLE_DATE = "java.sql.Timestamp";
	public static final String TABLE_TIMESTAMP = "oracle.sql.TIMESTAMP";
	public static final String JAVA_DATE = "java.util.Date";
	public static final String JAVA_BigDecimal = "java.math.BigDecimal";
	public static final String JAVA_DOUBLE = "java.lang.Double";
	public static final String JAVA_LONG = "java.lang.Long";

	private static Map<String, String> map = null;
	
	public static void initMap() {
		map = new HashMap<String, String>();
		map.put(TABLE_NUMBER, JAVA_DOUBLE);
		map.put(TABLE_DATE, JAVA_DATE);
		map.put(TABLE_TIMESTAMP, JAVA_DATE);
	}
	
	public static String map(String in) {
		if (map == null) {
			initMap();
		}
		String value = map.get(in);
		if (value == null) {
			return in;
		} else {
			return value;
		}
	}
	
	public static String map(Column col) {
		BigDecimal length = col.getLength();
		if (col.getJavaType().equalsIgnoreCase(TABLE_NUMBER)){
			if (col.getScale() != null && col.getScale() > 0) {
				return JAVA_DOUBLE;
			}
/*			if (col.getPrecision() != null && col.getPrecision() > 18) {
				return JAVA_LONG;
			}*/
			return JAVA_LONG;
		}
		return map(col.getJavaType());
	}
}
